<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <!-- 1.methods -->
        <h2>{{ getFullname() }}</h2>
        <h2>{{ getFullname() }}</h2>
        <h2>{{ getFullname() }}</h2>

        <!-- 2.computed -->
        <h2>{{ fullname }}</h2>
        <h2>{{ fullname }}</h2>
        <h2>{{ fullname }}</h2>

        <button @click="changeLastname">修改lastName</button>
    </div>

    <script src="./lib/Vue.js"></script>
    <script>
        const app = Vue.createApp({
            data() {
                return{
                  firstName:"kobe",
                  lastName:"bryant"
                }
            },
            methods:{
              getFullname() {
                console.log('methods');//执行三次
                return this.firstName + " " + this.lastName
              },
              changeLastname() {
                this.lastName = "why"
              }
            },
            computed: {
              fullname() {
                console.log('computed');//执行两次，计算属性有缓存
                return this.firstName + " " + this.lastName
              }
            }
        })
        app.mount("#app")
    </script>
</body>
</html>